<template>
  <div id="client">
    <p style="margin-bottom: 20px">
      请输入：
      <el-input
        style="width: 200px; margin-left: 10px; margin-right: 20px"
        placeholder="请输入客户名或者单据编号"
        v-model="orderNum"
        clearable
      >
      </el-input>
      &nbsp;&nbsp;
      销售人员：<el-input
        style="width: 200px; margin-left: 10px; margin-right: 20px"
        placeholder="请输入单据编号、客户名或备注"
        v-model="saler"
        clearable
      >
      </el-input
      >
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

    </p>
    <p style="">
      
     &nbsp;&nbsp;&nbsp; 审核状态<el-input
        style="width: 200px; margin-left: 10px; margin-right: 20px"
        placeholder="请输入审核状态"
        v-model="status"
        clearable
      >
      </el-input
      ><el-dropdown>
        <span class="el-dropdown-link">
          <i class="el-icon-arrow-down el-icon--right"></i>
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item>已审核</el-dropdown-item>
          <el-dropdown-item>未审核</el-dropdown-item>
        </el-dropdown-menu> </el-dropdown
      >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <el-button type="primary">查询</el-button>
    </p>
    <el-divider></el-divider>
    <div style="margin-bottom: 20px; margin-right: 20px; float: right">
      <el-button type="success">审核</el-button>&nbsp;&nbsp;&nbsp;
      <el-button>反审核</el-button>&nbsp;&nbsp;&nbsp;
    </div>

    <div class="client-content">
      <el-table
        height="400px"
        :data="pageInfo.list"
        border
        style="width: 100%; font-size: 13px"
      > <el-table-column prop="clientName" label="客户名称" width="150">
        </el-table-column>
        <el-table-column prop="orderDate" label="订单日期" width="150">
        </el-table-column>
        <el-table-column prop="orderNum" label="关联销货单号" width="120">
        </el-table-column>
        <el-table-column prop="documentNum" label="订单编号" width="120">
        </el-table-column>
        <el-table-column prop="predocumentNum" label="关联预收款单号" width="120">
        </el-table-column>
        <el-table-column prop="saler" label="销售人员" width="120" :formatter="saleserFormatter">
        </el-table-column>
        <el-table-column prop="allPrice" label="优惠后金额" width="120">
        </el-table-column>
        <el-table-column prop="prepared" label="制单人" width="120">
        </el-table-column>
        <el-table-column prop="remark" label="备注" width="120">
        </el-table-column>
<el-table-column prop="status" label="审核状态" width="120">
  <template slot-scope="scope">
    <el-button
      :type="scope.row.status === 1 ? 'success' : 'danger'"
      @click="toggleReviewStatus(scope.row)">
      {{ scope.row.status === 1 ? '已审核' : '未审核' }}
    </el-button>
  </template>
</el-table-column>
        <el-table-column fixed="right" label="操作" width="100">
          <template slot-scope="scope">
            <el-button @click="handleClick(scope.row) " type="text" size="small"
              >编辑</el-button
            >
            <el-button type="text" size="small" @click="handledelete(scope.row) ">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <el-pagination
      style="margin-top: 20px"
      background
      layout="prev, pager, next, jumper, ->, total"
      :current-page="currentPage"
      :page-size="this.pageInfo.pageSize"
      :total="pageInfo.total"
      @current-change="handleCurrentChange"
    >
    </el-pagination>

  </div>
</template>

<script>
export default {
  name: "SaleOrdersList",
  data() {
    return {
      shenhe: "",
      jieshidate: "",
      zongshuru: "",
      salemen:[],
     pageInfo: "",
      dialogFormVisible1: false,
     tableData: [],
      checkAll: false,
      selectedOptions: [],
      options: ["未出库", "部分出库", "全出库", "已关闭"],
      isIndeterminate: false,
    };
  },
  methods: {
     toggleReviewStatus(row) {
      if(confirm("是否审核")){
  const documentNum=row.documentNum;
       let saleOrder=this.pageInfo.list.find(item=> item.documentNum === documentNum);
       this.axios({
        url:'/sale/saleOrder/verse',
        data:{
          ...saleOrder
        },
        method:'post'
       }).then(rs =>{
        if(rs.data.status==true){
          alert("审核成功")
           this.getList(this.pageInfo.pageNum,5)
        }else{
          alert("审核失败")
        }
       })
      }
     
  },
  handledelete(id){
          if(confirm("是否删除")){
            this.axiso({
              url:'/sale/saleOrder/delete',
              params:{
                orderId:id
              }
            }).then(rs=>{
              alert(rs.data.isDelete)
            })
          }
  },
    handleCheckedCitiesChange(value) {
      const checkedCount = value.length;
      this.checkAll = checkedCount === this.options.length;
      this.isIndeterminate =
        checkedCount > 0 && checkedCount < this.options.length;
    },
        handleClick(row) {
      console.log(row);
      const id = row.orderId;
     
      this.$router.push({ name: "SaleOrders", query: { id: id } });
    },
       saleserFormatter(row, column, cellValue) {
    const saleser = this.salemen.find(s => s.employeeCode === cellValue);
    return saleser ? saleser.employeeName: cellValue;
  },
   getSaler() {
      this.axios({
        url: "/info/employee/listAll",
      }).then((rs) => {
        this.salemen = rs.data.list;
        console.log("saleMan", rs.data);
      });
    },
    getList(newPage,pageSize){
        this.axios({
          url:'/sale/saleOrder/list',
           params:{
            pageNum:newPage,
          pageSize:pageSize,
           
           }
        }).then(rs=>{
          this.pageInfo=rs.data.pageInfo
          this.tabledata=rs.data.pageInfo.list
          console.log(rs.data.pageInfo.list)
        })
    },
    handleCurrentChange(newPage) {
      this.getList(newPage, this.pageInfo.pageSize);
    },
    goto(to) {
      this.$router.push(to);
    },
    
  },
   
  watch: {
    selectedOptions(value) {
      this.handleCheckedCitiesChange(value);
    },
  },created:function() {
    this.getList(1,5)
      this.getSaler()
  }
};
</script>

<style scoped>
.el-button el-button--default el-popover__reference {
  margin-right: 20px;
}

tr {
  border: 1px solid black;
}
.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
}
.el-icon-arrow-down {
  font-size: 12px;
}
</style>